Public Class F_JournalEntry
    Dim WithEvents SBO_Application As SAPbouiCOM.Application
    Dim Ocompany As SAPbobsCOM.Company
    Sub New(ByVal ocompany1 As SAPbobsCOM.Company, ByVal sbo_application1 As SAPbouiCOM.Application)
        SBO_Application = sbo_application1
        Ocompany = ocompany1
    End Sub
    Private Sub SBO_Application_FormDataEvent(ByRef BusinessObjectInfo As SAPbouiCOM.BusinessObjectInfo, ByRef BubbleEvent As Boolean) Handles SBO_Application.FormDataEvent
        Try
            If BusinessObjectInfo.FormTypeEx = 141 Then
                If BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD And BusinessObjectInfo.BeforeAction = False And BusinessObjectInfo.ActionSuccess = True Then
                    Dim DocEntrySBO As Integer = 0
                    oRecordSet2 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                    oRecordSet2.DoQuery("SELECT Max(cast(DocEntry as int))  FROM OPCH")
                    DocEntrySBO = oRecordSet2.Fields.Item(0).Value
                    If DocEntrySBO = (DocEtry + 1) Then
                        JournalEntry(DocEntrySBO)
                    End If
                ElseIf BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD And BusinessObjectInfo.BeforeAction = True Then
                    oRecordSet2 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                    oRecordSet2.DoQuery("SELECT Max(cast(DocEntry as int))  FROM OPCH")
                    DocEtry = oRecordSet2.Fields.Item(0).Value
                End If
            ElseIf BusinessObjectInfo.FormTypeEx = 181 Then
                If BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD And BusinessObjectInfo.BeforeAction = False And BusinessObjectInfo.ActionSuccess = True Then
                    Dim DocEntrySBO As Integer = 0
                    oRecordSet2 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                    oRecordSet2.DoQuery("SELECT Max(cast(DocEntry as int))  FROM ORPC")
                    DocEntrySBO = oRecordSet2.Fields.Item(0).Value
                    If DocEntrySBO = (DocEtry + 1) Then
                        JournalEntry_CN(DocEntrySBO)
                    End If
                ElseIf BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD And BusinessObjectInfo.BeforeAction = True Then
                    oRecordSet2 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                    oRecordSet2.DoQuery("SELECT Max(cast(DocEntry as int))  FROM ORPC")
                    DocEtry = oRecordSet2.Fields.Item(0).Value
                End If
            End If
        Catch ex As Exception
            Functions.WriteLog("Class:F_JournalEntry" + " Function:SBO_Application_FormDataEvent" + " Error Message:" + ex.ToString)
        End Try

    End Sub
    Private Sub JournalEntry_CN(ByVal DocEntry As String)
        Try
            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            oRecordSet.DoQuery("SELECT [TransId],U_AP_EXCH_RATE,U_AP_TAX_AMT,DocRate FROM ORPC WHERE DocEntry='" & DocEntry & "'")
            oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            Dim ExRate As Double = 0
            Dim TaxAmt As Double = 0
            Dim DocRate As Double = 0
            ExRate = oRecordSet.Fields.Item("U_AP_EXCH_RATE").Value
            TaxAmt = oRecordSet.Fields.Item("U_AP_TAX_AMT").Value
            DocRate = oRecordSet.Fields.Item("DocRate").Value
            oRecordSet1.DoQuery("SELECT T0.[Project], T0.[Ref2], T0.[Ref3], T1.[Project] ProjectLine, T1.[Ref1] 'Ref1_L', T1.[Ref2] 'Ref2_L', T1.[Ref3Line], T1.[LineMemo], T1.[OcrCode2], T1.[OcrCode3], [OcrCode4], T1.[OcrCode5],T1.[ProfitCode],T0.[RefDate], T0.[DueDate], T0.[TaxDate], T0.[Memo] , 'PC' 'Indicator' ,T0.Ref1,T0.[TransId], T1.[Line_ID],CASE WHEN T1.[Account]= T1.[ShortName]  THEN 'N' ELSE 'Y' END as 'SN',T1.[ShortName] ,CASE WHEN T1.[SYSCred] <> 0 THEN 'Credit' ELSE 'Debit' END AS 'SIDE',(CASE WHEN isnull(T1.[FCCurrency],'') <> '' AND T1.[FCCredit]=0  THEN T1.[FCDebit] WHEN isnull(T1.[FCCurrency],'') = '' AND T1.[Credit]=0  THEN T1.[Debit] WHEN isnull(T1.[FCCurrency],'') <> '' AND T1.[FCDebit]=0  THEN T1.[FCCredit] WHEN isnull(T1.[FCCurrency],'') = '' AND T1.[Debit]=0  THEN T1.[Credit] END)  * " & ExRate & "- (CASE WHEN T1.[SYSCred] = 0 THEN T1.[SYSDeb] ELSE T1.[SYSCred] END)As 'LOCALAMOUNT',CASE WHEN T1.[SYSCred] = 0 THEN T1.[SYSDeb] ELSE T1.[SYSCred] END AS 'SYSTEMAMOUNT',CASE WHEN isnull(T1.[FCCurrency],'') <> '' THEN (((T1.[BaseSum]*" & ExRate & ")/" & DocRate & ")- T1.[SYSBaseSum]) ELSE ((T1.[BaseSum]*" & ExRate & ")- T1.[SYSBaseSum]) END AS  'BASEAMOUNT',ISNULL(T1.VatGroup,'') 'VatGroup' FROM OJDT T0  INNER JOIN JDT1 T1 ON T0.TransId = T1.TransId WHERE T1.[TransId]='" & oRecordSet.Fields.Item(0).Value.ToString & "' ORDER BY T0.[TransId], T1.[Line_ID] ASC")
            Dim oJV As SAPbobsCOM.JournalEntries
            oJV = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries)
            Dim i As Integer = 0
            Dim TotDebit As Double = 0
            Dim TotCredit As Double = 0
            If oRecordSet1.RecordCount = 0 Then
                Exit Sub
            End If
            oJV.ReferenceDate = oRecordSet1.Fields.Item("RefDate").Value
            oJV.DueDate = oRecordSet1.Fields.Item("DueDate").Value
            oJV.TaxDate = oRecordSet1.Fields.Item("TaxDate").Value
            oJV.Memo = oRecordSet1.Fields.Item("Memo").Value
            oJV.Reference = oRecordSet1.Fields.Item("Ref1").Value
            oJV.Indicator = oRecordSet1.Fields.Item("Indicator").Value
            oJV.ProjectCode = oRecordSet1.Fields.Item("Project").Value
            oJV.Reference2 = oRecordSet1.Fields.Item("Ref2").Value
            oJV.Reference3 = oRecordSet1.Fields.Item("Ref3").Value

            Dim K As Integer
            Dim Credit As Double = 0
            Dim Debit As Double = 0
            For i = 1 To oRecordSet1.RecordCount
                If i <> 1 Then
                    oJV.Lines.Add()
                End If
                oJV.Lines.SetCurrentLine(i - 1)
                oJV.Lines.ProjectCode = oRecordSet1.Fields.Item("ProjectLine").Value
                oJV.Lines.Reference1 = oRecordSet1.Fields.Item("Ref1_L").Value
                oJV.Lines.Reference2 = oRecordSet1.Fields.Item("Ref2_L").Value
                '  oJV.Lines.Reference3 = oRecordSet1.Fields.Item("Ref3Line").Value

                oJV.Lines.LineMemo = oRecordSet1.Fields.Item("LineMemo").Value
                oJV.Lines.CostingCode = oRecordSet1.Fields.Item("ProfitCode").Value
                oJV.Lines.CostingCode2 = oRecordSet1.Fields.Item("OcrCode2").Value
                oJV.Lines.CostingCode3 = oRecordSet1.Fields.Item("OcrCode3").Value
                oJV.Lines.CostingCode4 = oRecordSet1.Fields.Item("OcrCode4").Value
                oJV.Lines.CostingCode5 = oRecordSet1.Fields.Item("OcrCode5").Value
                If oRecordSet1.Fields.Item("SIDE").Value = "Debit" Then 'Debit
                    If oRecordSet1.Fields.Item("SN").Value = "Y" Then
                        oJV.Lines.ShortName = oRecordSet1.Fields.Item("ShortName").Value
                    Else
                        oJV.Lines.AccountCode = oRecordSet1.Fields.Item("ShortName").Value
                    End If
                    Credit = Math.Round(oRecordSet1.Fields.Item("LOCALAMOUNT").Value, 2)
                    oJV.Lines.DebitSys = Math.Round(Credit, 2)
                    TotCredit = TotCredit + Math.Round(Credit, 2)
                    TotCredit = Math.Round(TotCredit, 2)
                    If oRecordSet1.Fields.Item("VatGroup").Value <> "" Then
                        oJV.Lines.TaxGroup = oRecordSet1.Fields.Item("VatGroup").Value
                        oJV.Lines.SystemBaseAmount = oRecordSet1.Fields.Item("BASEAMOUNT").Value
                    End If
                ElseIf oRecordSet1.Fields.Item("SIDE").Value = "Credit" Then
                    If oRecordSet1.Fields.Item("SN").Value = "Y" Then
                        oJV.Lines.ShortName = oRecordSet1.Fields.Item("ShortName").Value
                    Else
                        oJV.Lines.AccountCode = oRecordSet1.Fields.Item("ShortName").Value
                    End If
                    If i = oRecordSet1.RecordCount Then
                        Debit = TotCredit - TotDebit
                    ElseIf oRecordSet1.Fields.Item("VatGroup").Value <> "SI" Then
                        TotDebit = Math.Round(TotDebit, 2) + Math.Round(oRecordSet1.Fields.Item("LOCALAMOUNT").Value, 2)
                        Debit = oRecordSet1.Fields.Item("LOCALAMOUNT").Value
                    Else
                        TotDebit = Math.Round(TotDebit, 2) + (Math.Round(TaxAmt, 2) - Math.Round(oRecordSet1.Fields.Item("SYSTEMAMOUNT").Value, 2))
                        TotDebit = Math.Round(TotDebit, 2)
                        Debit = TaxAmt - oRecordSet1.Fields.Item("SYSTEMAMOUNT").Value
                    End If
                    Debit = Math.Round(Debit, 2)
                    oJV.Lines.CreditSys = Math.Round(Debit, 2)
                    If oRecordSet1.Fields.Item("VatGroup").Value <> "" Then
                        oJV.Lines.TaxGroup = oRecordSet1.Fields.Item("VatGroup").Value
                        oJV.Lines.SystemBaseAmount = oRecordSet1.Fields.Item("BASEAMOUNT").Value
                    End If
                End If
                oRecordSet1.MoveNext()
            Next
            K = oJV.Add()
            If K <> 0 Then
                Dim st As String = ""
                Ocompany.GetLastError(K, st)
                If st = "Transaction Without Amount " Then
                    st = ""
                End If
                oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet.DoQuery("UPDATE ORPC set U_JEST='N',U_ERRMSG='" & st & "' WHERE DocEntry='" & DocEntry & "'")
            Else
                oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet.DoQuery("UPDATE ORPC set U_JEST='Y' WHERE DocEntry='" & DocEntry & "'")
            End If
            oJV = Nothing
            oRecordSet = Nothing
            oRecordSet1 = Nothing
            oRecordSet2 = Nothing
            GC.Collect()
        Catch ex As Exception
            Functions.WriteLog("Class:F_JournalEntry" + " Function:JournalEntry" + " Error Message:" + ex.ToString)
        End Try
    End Sub
    Private Sub JournalEntry(ByVal DocEntry As String)
        Try
            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            oRecordSet.DoQuery("SELECT [TransId],U_AP_EXCH_RATE,U_AP_TAX_AMT,DocRate FROM OPCH WHERE DocEntry='" & DocEntry & "'")
            oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            Dim ExRate As Double = 0
            Dim TaxAmt As Double = 0
            Dim DocRate As Double = 0
            ExRate = oRecordSet.Fields.Item("U_AP_EXCH_RATE").Value
            TaxAmt = oRecordSet.Fields.Item("U_AP_TAX_AMT").Value
            DocRate = oRecordSet.Fields.Item("DocRate").Value
            oRecordSet1.DoQuery("SELECT T0.[Project], T0.[Ref2], T0.[Ref3], T1.[Project] ProjectLine, T1.[Ref1] 'Ref1_L', T1.[Ref2] 'Ref2_L', T1.[Ref3Line], T1.[LineMemo], T1.[OcrCode2], T1.[OcrCode3], [OcrCode4], T1.[OcrCode5],T1.[ProfitCode],T0.[RefDate], T0.[DueDate], T0.[TaxDate], T0.[Memo] , 'PU' 'Indicator' ,T0.Ref1,T0.[TransId], T1.[Line_ID],CASE WHEN T1.[Account]= T1.[ShortName]  THEN 'N' ELSE 'Y' END as 'SN',T1.[ShortName] ,CASE WHEN T1.[SYSCred] <> 0 THEN 'Credit' ELSE 'Debit' END AS 'SIDE',(CASE WHEN isnull(T1.[FCCurrency],'') <> '' AND T1.[FCCredit]=0  THEN T1.[FCDebit] WHEN isnull(T1.[FCCurrency],'') = '' AND T1.[Credit]=0  THEN T1.[Debit] WHEN isnull(T1.[FCCurrency],'') <> '' AND T1.[FCDebit]=0  THEN T1.[FCCredit] WHEN isnull(T1.[FCCurrency],'') = '' AND T1.[Debit]=0  THEN T1.[Credit] END)  * " & ExRate & "- (CASE WHEN T1.[SYSCred] = 0 THEN T1.[SYSDeb] ELSE T1.[SYSCred] END)As 'LOCALAMOUNT',CASE WHEN T1.[SYSCred] = 0 THEN T1.[SYSDeb] ELSE T1.[SYSCred] END AS 'SYSTEMAMOUNT',CASE WHEN isnull(T1.[FCCurrency],'') <> '' THEN (((T1.[BaseSum]*" & ExRate & ")/" & DocRate & ")- T1.[SYSBaseSum]) ELSE ((T1.[BaseSum]*" & ExRate & ")- T1.[SYSBaseSum]) END AS  'BASEAMOUNT',ISNULL(T1.VatGroup,'') 'VatGroup' FROM OJDT T0  INNER JOIN JDT1 T1 ON T0.TransId = T1.TransId WHERE T1.[TransId]='" & oRecordSet.Fields.Item(0).Value.ToString & "' ORDER BY T0.[TransId], T1.[Line_ID] ASC")
            Dim oJV As SAPbobsCOM.JournalEntries
            oJV = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries)
            Dim i As Integer = 0
            Dim TotDebit As Double = 0
            Dim TotCredit As Double = 0
            If oRecordSet1.RecordCount = 0 Then
                Exit Sub
            End If
            oJV.ReferenceDate = oRecordSet1.Fields.Item("RefDate").Value
            oJV.DueDate = oRecordSet1.Fields.Item("DueDate").Value
            oJV.TaxDate = oRecordSet1.Fields.Item("TaxDate").Value
            oJV.Memo = oRecordSet1.Fields.Item("Memo").Value
            oJV.Reference = oRecordSet1.Fields.Item("Ref1").Value
            oJV.Indicator = oRecordSet1.Fields.Item("Indicator").Value
            oJV.ProjectCode = oRecordSet1.Fields.Item("Project").Value
            oJV.Reference2 = oRecordSet1.Fields.Item("Ref2").Value
            oJV.Reference3 = oRecordSet1.Fields.Item("Ref3").Value

            Dim K As Integer
            Dim Credit As Double = 0
            Dim Debit As Double = 0
            For i = 1 To oRecordSet1.RecordCount
                If i <> 1 Then
                    oJV.Lines.Add()
                End If
                oJV.Lines.SetCurrentLine(i - 1)
                oJV.Lines.ProjectCode = oRecordSet1.Fields.Item("ProjectLine").Value
                oJV.Lines.Reference1 = oRecordSet1.Fields.Item("Ref1_L").Value
                oJV.Lines.Reference2 = oRecordSet1.Fields.Item("Ref2_L").Value
                '  oJV.Lines.Reference3 = oRecordSet1.Fields.Item("Ref3Line").Value

                oJV.Lines.LineMemo = oRecordSet1.Fields.Item("LineMemo").Value
                oJV.Lines.CostingCode = oRecordSet1.Fields.Item("ProfitCode").Value
                oJV.Lines.CostingCode2 = oRecordSet1.Fields.Item("OcrCode2").Value
                oJV.Lines.CostingCode3 = oRecordSet1.Fields.Item("OcrCode3").Value
                oJV.Lines.CostingCode4 = oRecordSet1.Fields.Item("OcrCode4").Value
                oJV.Lines.CostingCode5 = oRecordSet1.Fields.Item("OcrCode5").Value
                If oRecordSet1.Fields.Item("SIDE").Value = "Credit" Then
                    If oRecordSet1.Fields.Item("SN").Value = "Y" Then
                        oJV.Lines.ShortName = oRecordSet1.Fields.Item("ShortName").Value
                    Else
                        oJV.Lines.AccountCode = oRecordSet1.Fields.Item("ShortName").Value
                    End If
                    Credit = Math.Round(oRecordSet1.Fields.Item("LOCALAMOUNT").Value, 2)
                    oJV.Lines.CreditSys = Math.Round(Credit, 2)
                    TotCredit = TotCredit + Math.Round(Credit, 2)
                    TotCredit = Math.Round(TotCredit, 2)
                ElseIf oRecordSet1.Fields.Item("SIDE").Value = "Debit" Then
                    If oRecordSet1.Fields.Item("SN").Value = "Y" Then
                        oJV.Lines.ShortName = oRecordSet1.Fields.Item("ShortName").Value
                    Else
                        oJV.Lines.AccountCode = oRecordSet1.Fields.Item("ShortName").Value
                    End If
                    If i = oRecordSet1.RecordCount Then
                        Debit = TotCredit - TotDebit
                    ElseIf oRecordSet1.Fields.Item("VatGroup").Value <> "SI" Then
                        TotDebit = Math.Round(TotDebit, 2) + Math.Round(oRecordSet1.Fields.Item("LOCALAMOUNT").Value, 2)
                        Debit = oRecordSet1.Fields.Item("LOCALAMOUNT").Value
                    Else
                        TotDebit = Math.Round(TotDebit, 2) + (Math.Round(TaxAmt, 2) - Math.Round(oRecordSet1.Fields.Item("SYSTEMAMOUNT").Value, 2))
                        TotDebit = Math.Round(TotDebit, 2)
                        Debit = TaxAmt - oRecordSet1.Fields.Item("SYSTEMAMOUNT").Value
                    End If
                    Debit = Math.Round(Debit, 2)
                    oJV.Lines.DebitSys = Math.Round(Debit, 2)
                    If oRecordSet1.Fields.Item("VatGroup").Value <> "" Then
                        oJV.Lines.TaxGroup = oRecordSet1.Fields.Item("VatGroup").Value
                        oJV.Lines.SystemBaseAmount = oRecordSet1.Fields.Item("BASEAMOUNT").Value
                    End If
                End If
                oRecordSet1.MoveNext()
            Next
            K = oJV.Add()
            If K <> 0 Then
                Dim st As String = ""
                Ocompany.GetLastError(K, st)
                If st = "Transaction Without Amount " Then
                    st = ""
                End If
                oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet.DoQuery("UPDATE OPCH set U_JEST='N',U_ERRMSG='" & st & "' WHERE DocEntry='" & DocEntry & "'")
            Else
                oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                oRecordSet.DoQuery("UPDATE OPCH set U_JEST='Y' WHERE DocEntry='" & DocEntry & "'")
            End If
            oJV = Nothing
            oRecordSet = Nothing
            oRecordSet1 = Nothing
            oRecordSet2 = Nothing
            GC.Collect()
        Catch ex As Exception
            Functions.WriteLog("Class:F_JournalEntry" + " Function:JournalEntry" + " Error Message:" + ex.ToString)
        End Try
    End Sub
    'Private Sub JournalEntry(ByVal DocEntry As String)
    '    Try
    '        oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
    '        oRecordSet.DoQuery("SELECT [TransId],U_AP_EXCH_RATE,U_AP_TAX_AMT FROM OPCH WHERE DocEntry='" & DocEntry & "'")
    '        oRecordSet1 = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
    '        Dim ExRate As Double = 0
    '        Dim TaxAmt As Double = 0
    '        ExRate = oRecordSet.Fields.Item("U_AP_EXCH_RATE").Value
    '        TaxAmt = oRecordSet.Fields.Item("U_AP_TAX_AMT").Value
    '        oRecordSet1.DoQuery("SELECT T0.Ref1,T0.[TransId], T1.[Line_ID],CASE WHEN T1.[Account]= T1.[ShortName]  THEN 'N' ELSE 'Y' END as 'SN',T1.[ShortName] ,CASE WHEN T1.[SYSCred] <> 0 THEN 'Credit' ELSE 'Debit' END AS 'SIDE',(CASE WHEN isnull(T1.[FCCurrency],'') <> '' AND T1.[FCCredit]=0  THEN T1.[FCDebit] WHEN isnull(T1.[FCCurrency],'') = '' AND T1.[Credit]=0  THEN T1.[Debit] WHEN isnull(T1.[FCCurrency],'') <> '' AND T1.[FCDebit]=0  THEN T1.[FCCredit] WHEN isnull(T1.[FCCurrency],'') = '' AND T1.[Debit]=0  THEN T1.[Credit] END)  * " & ExRate & "- (CASE WHEN T1.[SYSCred] = 0 THEN T1.[SYSDeb] ELSE T1.[SYSCred] END)As 'LOCALAMOUNT',CASE WHEN T1.[SYSCred] = 0 THEN T1.[SYSDeb] ELSE T1.[SYSCred] END AS 'SYSTEMAMOUNT',((T1.[BaseSum]*" & ExRate & ")- T1.[SYSBaseSum])'BASEAMOUNT',ISNULL(T1.VatGroup,'') 'VatGroup' FROM OJDT T0  INNER JOIN JDT1 T1 ON T0.TransId = T1.TransId WHERE T1.[TransId]='" & oRecordSet.Fields.Item(0).Value.ToString & "' ORDER BY T0.[TransId], T1.[Line_ID] ASC")

    '        '  Dim oJV As SAPbobsCOM.JournalEntries = DirectCast(Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries), SAPbobsCOM.JournalEntries)
    '        Dim oJV As SAPbobsCOM.JournalEntries
    '        oJV = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries)

    '        'Dim oJV As SAPbobsCOM.IJournalEntries
    '        'oJV = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries)
    '        Dim i As Integer = 0
    '        Dim TotDebit As Double = 0
    '        Dim TotCredit As Double = 0
    '        If oRecordSet1.RecordCount = 0 Then
    '            Exit Sub
    '        End If



    '        oJV.JournalEntries.Reference = "10" 'oRecordSet1.Fields.Item("Ref1").Value.ToString
    '        oJV.JournalEntries.Indicator = "PU"
    '        For i = 1 To oRecordSet1.RecordCount
    '            If oRecordSet1.Fields.Item("SIDE").Value = "Credit" Then
    '                If oRecordSet1.Fields.Item("SN").Value = "Y" Then
    '                    oJV.JournalEntries.Lines.ShortName = oRecordSet1.Fields.Item("ShortName").Value
    '                Else
    '                    oJV.JournalEntries.Lines.AccountCode = oRecordSet1.Fields.Item("ShortName").Value
    '                End If
    '                oJV.JournalEntries.Lines.CreditSys = oRecordSet1.Fields.Item("LOCALAMOUNT").Value
    '                'If oRecordSet1.Fields.Item("VatGroup").Value <> "" Then
    '                '    oJV.JournalEntries.Lines.TaxGroup = oRecordSet1.Fields.Item("VatGroup").Value
    '                '    oJV.JournalEntries.Lines.SystemBaseAmount = oRecordSet1.Fields.Item("BASEAMOUNT").Value
    '                'End If
    '                TotCredit = TotCredit + oRecordSet1.Fields.Item("LOCALAMOUNT").Value
    '                TotCredit = Math.Round(TotCredit, 2)
    '                oJV.JournalEntries.Lines.Add()
    '            ElseIf oRecordSet1.Fields.Item("SIDE").Value = "Debit" Then
    '                If oRecordSet1.Fields.Item("SN").Value = "Y" Then
    '                    oJV.JournalEntries.Lines.ShortName = oRecordSet1.Fields.Item("ShortName").Value
    '                Else
    '                    oJV.JournalEntries.Lines.AccountCode = oRecordSet1.Fields.Item("ShortName").Value
    '                End If

    '                If i = oRecordSet1.RecordCount Then
    '                    oJV.JournalEntries.Lines.DebitSys = TotCredit - TotDebit
    '                ElseIf oRecordSet1.Fields.Item("VatGroup").Value <> "SI" Then
    '                    TotDebit = Math.Round(TotDebit, 2) + Math.Round(oRecordSet1.Fields.Item("LOCALAMOUNT").Value, 2)
    '                    oJV.JournalEntries.Lines.DebitSys = oRecordSet1.Fields.Item("LOCALAMOUNT").Value
    '                Else
    '                    TotDebit = Math.Round(TotDebit, 2) + (Math.Round(TaxAmt, 2) - oRecordSet1.Fields.Item("SYSTEMAMOUNT").Value)
    '                    TotDebit = Math.Round(TotDebit, 2)
    '                    oJV.JournalEntries.Lines.DebitSys = TaxAmt - oRecordSet1.Fields.Item("SYSTEMAMOUNT").Value
    '                End If
    '                If oRecordSet1.Fields.Item("VatGroup").Value <> "" Then
    '                    oJV.JournalEntries.Lines.TaxGroup = oRecordSet1.Fields.Item("VatGroup").Value
    '                    oJV.JournalEntries.Lines.SystemBaseAmount = oRecordSet1.Fields.Item("BASEAMOUNT").Value
    '                End If
    '                oJV.JournalEntries.Lines.Add()
    '            End If
    '            oRecordSet1.MoveNext()
    '        Next

    '        Dim K As Integer
    '        k = oJV.Add()

    '        If K <> 0 Then
    '            Dim st As String = ""
    '            Ocompany.GetLastError(K, st)
    '            SBO_Application.MessageBox(st)
    '        End If


    '    Catch ex As Exception
    '        Functions.WriteLog("Class:F_JournalEntry" + " Function:JournalEntry" + " Error Message:" + ex.ToString)
    '    End Try
    'End Sub
    ' oRecordSet1.DoQuery("SELECT T0.[TransId], T1.[Line_ID],CASE WHEN T1.[Account]= T1.[ShortName]  THEN 'N' ELSE'Y' END as 'ShortName',T1.[ShortName] ,CASE WHEN T1.[SYSCred] <> 0 THEN 'Credit' ELSE 'Debit' END AS 'SIDE',CASE WHEN isnull(T1.[FCCurrency],'') <> '' AND T1.[FCCredit]=0 THEN T1.[FCDebit] WHEN isnull(T1.[FCCurrency],'') = '' AND T1.[Credit]=0 THEN T1.[Debit] WHEN isnull(T1.[FCCurrency],'') <> '' AND T1.[FCDebit] =0 THEN T1.[FCCredit] WHEN isnull(T1.[FCCurrency],'') = '' AND T1.[Debit] =0 THEN T1.[Credit] END As 'LOCAL AMOUNT',CASE WHEN [SYSCred]=0 THEN T1.[SYSDeb] ELSE T1.[SYSCred] END AS 'SYSTEM AMOUNT',T1.[BaseSum], T1.[SYSBaseSum],ISNULL(T1.VatGroup,'') 'VatGroup' FROM OJDT T0  INNER JOIN JDT1 T1 ON T0.TransId = T1.TransId WHERE T1.[TransId] ='" & oRecordSet.Fields.Item(0).Value.ToString & "' ORDER BY T0.[TransId], T1.[Line_ID] ASC")
End Class
